//
//  XLGHeadImageDownloadQueue.m
//  etionCBLogic
//
//  Created by wjxfhxy on 14-5-30.
//  Copyright (c) 2014年 GuangZhouXuanWu. All rights reserved.
//

#import "XLGHeadImageDownloadQueue.h"

#import "XLGHeadImageDownloadQueueInternal.h"

NSString *const XLGHeadImageDownloadQueueHeadImageDownloadResultNotification = @"XLGHeadImageDownloadQueueHeadImageDownloadResultNotification";

NSString *const XLGHeadImageDownloadQueueHeadImageDownloadResultResultKey = @"XLGHeadImageDownloadQueueHeadImageDownloadResultResultKey";

NSString *const XLGHeadImageDownloadQueueHeadImageDownloadResultURLKey = @"XLGHeadImageDownloadQueueHeadImageDownloadResultURLKey";

NSString *const XLGHeadImageDownloadQueueHeadImageDownloadResultPathKey = @"XLGHeadImageDownloadQueueHeadImageDownloadResultPathKey";

NSString *const HeadImageDownQueueDefaultQueue = @"HeadImageDownQueueDefaultQueue";

@interface XLGHeadImageDownloadQueue ()

@end

@implementation XLGHeadImageDownloadQueue

static NSMutableDictionary *s_dicQueue;

+(void)initHeadImageDownloadQueue
{
    if(s_dicQueue == nil)
    {
        s_dicQueue = [NSMutableDictionary new];
        [s_dicQueue setObject:[[XLGHeadImageDownloadQueueInternal new] autorelease_mm] forKey:HeadImageDownQueueDefaultQueue];
    }
}

+(void)releaseHeadImageDownloadQueue
{
    [s_dicQueue enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop)
    {
        [(XLGHeadImageDownloadQueueInternal*)obj terminate];
    }];
    ReleaseObj(s_dicQueue);
}

+(XLGHeadImageDownloadQueueInternal*)getInternalForKey:(NSString*)key
{
    XLGHeadImageDownloadQueueInternal *internal = [s_dicQueue objectForKey:key];
    if(internal == nil)
    {
        internal = [XLGHeadImageDownloadQueueInternal new];
        [s_dicQueue setObject:internal forKey:key];
    }
    return internal;
}

+(void)deleteAllQueueHeadImageCache
{
    [s_dicQueue enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop)
    {
        [(XLGHeadImageDownloadQueueInternal*)obj deleteAllHeadImage];
    }];
}

+(void)clearAllQueueAll
{
    [s_dicQueue enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop)
    {
        [(XLGHeadImageDownloadQueueInternal*)obj clearAll];
    }];
}

@end

@implementation XLGHeadImageDownloadQueue (AssignQueue)

+(void)setLocalStorePath:(NSString*)path forKey:(NSString*)key
{
    if([XMSFileHelper isDirExist:path] != YES)
        [XMSFileHelper createDir:path];
    [XLGHeadImageDownloadQueue getInternalForKey:key].localPath = path;
}

+(XLGHeadImageCache*)checkOrStartDownloadHeadImageWhenAddHeadImageURL:(NSString*)headImageURL forKey:(NSString*)key
{
    return [[XLGHeadImageDownloadQueue getInternalForKey:key] checkOrStartDownloadHeadImageWhenAddHeadImageURL:headImageURL];
}

+(BOOL)setOrStartDownloadHeadImageWhenAddHeadImageURL:(NSString*)headImageURL inImageView:(UIImageView*)imageView tag:(NSString*)tag forKey:(NSString*)key
{
    return [[XLGHeadImageDownloadQueue getInternalForKey:key] setOrStartDownloadHeadImageWhenAddHeadImageURL:headImageURL inImageView:imageView tag:tag];
}

+(NSString*)isHeadImageExist:(NSString*)headImageURL forKey:(NSString*)key
{
    return [[XLGHeadImageDownloadQueue getInternalForKey:key] isHeadImageExist:headImageURL];
}

+(XLGHeadImageCache*)setCacheWithHeadImageURL:(NSString*)headImageURL andHeadImagePath:(NSString*)headImagePath forKey:(NSString*)key
{
    return [[XLGHeadImageDownloadQueue getInternalForKey:key] setCacheWithHeadImageURL:headImageURL andHeadImagePath:headImagePath];
}

+(XLGHeadImageCache*)checkDownloadHeadImageWithHeadImageURL:(NSString *)headImageURL forKey:(NSString *)key
{
    return [[XLGHeadImageDownloadQueue getInternalForKey:key] checkDownloadHeadImageWithHeadImageURL:headImageURL];
}

+(void)deleteHeadImage:(NSString*)headImageURL forKey:(NSString*)key
{
    [[XLGHeadImageDownloadQueue getInternalForKey:key] deleteHeadImage:headImageURL];
}

+(void)deleteAllHeadImageForKey:(NSString*)key
{
    [[XLGHeadImageDownloadQueue getInternalForKey:key] deleteAllHeadImage];
}

+(void)clearAllForKey:(NSString*)key
{
    [[XLGHeadImageDownloadQueue getInternalForKey:key] clearAll];
}

+(void)clearTag:(NSString*)tag forKey:(NSString*)key
{
    [[XLGHeadImageDownloadQueue getInternalForKey:key] clearTag:tag];
}

@end

@implementation XLGHeadImageDownloadQueue (DefaultQueue)

+(void)setLocalStorePath:(NSString*)path
{
    [XLGHeadImageDownloadQueue setLocalStorePath:path forKey:HeadImageDownQueueDefaultQueue];
}

+(XLGHeadImageCache*)checkOrStartDownloadHeadImageWhenAddHeadImageURL:(NSString*)headImageURL
{
    return [XLGHeadImageDownloadQueue checkOrStartDownloadHeadImageWhenAddHeadImageURL:headImageURL forKey:HeadImageDownQueueDefaultQueue];
}

+(XLGHeadImageCache*)isHeadImageExist:(NSString*)headImageURL
{
    return [XLGHeadImageDownloadQueue checkOrStartDownloadHeadImageWhenAddHeadImageURL:headImageURL forKey:HeadImageDownQueueDefaultQueue];
}

+(XLGHeadImageCache*)setCacheWithHeadImageURL:(NSString *)headImageURL andHeadImagePath:(NSString *)headImagePath
{
    return [XLGHeadImageDownloadQueue setCacheWithHeadImageURL:headImageURL andHeadImagePath:headImagePath forKey:HeadImageDownQueueDefaultQueue];
}

+(XLGHeadImageCache*)checkDownloadHeadImageWithHeadImageURL:(NSString*)headImageURL
{
    return [XLGHeadImageDownloadQueue checkDownloadHeadImageWithHeadImageURL:headImageURL forKey:HeadImageDownQueueDefaultQueue];
}

+(void)deleteHeadImage:(NSString*)headImageURL;
{
    [XLGHeadImageDownloadQueue deleteHeadImage:headImageURL forKey:HeadImageDownQueueDefaultQueue];
}

+(void)deleteAllHeadImage
{
    [XLGHeadImageDownloadQueue deleteAllHeadImageForKey:HeadImageDownQueueDefaultQueue];
}

+(void)clearAll
{
    [XLGHeadImageDownloadQueue clearAllForKey:HeadImageDownQueueDefaultQueue];
}

@end

@implementation XLGHeadImageDownloadQueue (SetImageViewImage)

+(void)cacheImageView:(UIImageView*)imageView withImageURL:(NSString*)imageURL forKey:(NSString*)key
{
    
}

@end

